//
//  DataStore.m
//
//
//  Created by cztv on 13-3-6.
//  Copyright (c) 2013年 windo-soft. All rights reserved.
//


#import "DataStore.h"

static NSString *const kIsFirstLaunch = @"isFirstLaunch";
static NSString *const kDeviceToken = @"deviceToken";
static NSString *const kIsScored = @"isScored";

static NSString *const kUsername = @"username";
static NSString *const kPassword = @"password";
static NSString *const kCityname = @"cityname";
static NSString *const kShopid = @"shopid";
static NSString *const kShopname = @"shopname";

//static NSString *const kServerURL = @"serverURL";

@implementation DataStore

+ (DataStore *)sharedDataStore {
    static dispatch_once_t once;
    static DataStore *mInstance = nil;
    dispatch_once(&once, ^ {
        mInstance = [[DataStore alloc] init];
    });
    return mInstance;
}

////////////////////////////////////////////////////////////////////////////////////////////////////

- (void)setIsFirstLaunch:(BOOL)isFirstLaunch {
    [[NSUserDefaults standardUserDefaults] setBool:isFirstLaunch forKey:kIsFirstLaunch];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (BOOL)isFirstLaunch {
    return ![[NSUserDefaults standardUserDefaults] boolForKey:kIsFirstLaunch];
}

- (void)setIsScored:(BOOL)isScored {
    [[NSUserDefaults standardUserDefaults] setBool:isScored forKey:kIsScored];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (BOOL)isScored {
    return [[NSUserDefaults standardUserDefaults] boolForKey:kIsScored];
}

- (void)setDeviceToken:(NSData *)deviceToken {
    [[NSUserDefaults standardUserDefaults] setObject:deviceToken forKey:kDeviceToken];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSData *)deviceToken {
    NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:kDeviceToken];
    return data;
}

////////////////////////////////////////////////////////////////////////////////////////////////////

- (void)setUsername:(NSString *)username {
    [[NSUserDefaults standardUserDefaults] setObject:username forKey:kUsername];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSString *)username {
    NSString *string = [[NSUserDefaults standardUserDefaults] objectForKey:kUsername];
    return string ? string : @"";
}

- (void)setPassword:(NSString *)password {
    [[NSUserDefaults standardUserDefaults] setObject:password forKey:kPassword];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSString *)password {
    NSString *string = [[NSUserDefaults standardUserDefaults] objectForKey:kPassword];
    return string ? string : @"";
}

////////////////////////////////////////////////////////////////////////////////////////////////////

- (void)setCityname:(NSString *)cityname {
    [[NSUserDefaults standardUserDefaults] setObject:cityname forKey:kCityname];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSString *)cityname {
    NSString *string = [[NSUserDefaults standardUserDefaults] objectForKey:kCityname];
    return string ? string : @"";
}

- (void)setShopid:(NSString *)shopid {
    [[NSUserDefaults standardUserDefaults] setObject:shopid forKey:kShopid];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSString *)shopid {
    NSString *string = [[NSUserDefaults standardUserDefaults] objectForKey:kShopid];
    return string ? string : @"";
}

- (void)setShopname:(NSString *)shopname {
    [[NSUserDefaults standardUserDefaults] setObject:shopname forKey:kShopname];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSString *)shopname {
    NSString *string = [[NSUserDefaults standardUserDefaults] objectForKey:kShopname];
    return string ? string : @"";
}



////创建md5签名 加密
//+(NSString*)createMd5Sign:(NSMutableDictionary*)dict
//{
//    NSMutableString *contentString  =[NSMutableString string];
//    NSArray *keys = [dict allKeys];
//    //按字母顺序排序
//    NSArray *sortedArray = [keys sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
//        return [obj1 compare:obj2 options:NSNumericSearch];
//    }];
//    //拼接字符串
//#warning 崩溃问题
//    DBLOG(@"sortedArray-->>%@",sortedArray);
//    for (NSString *categoryId in sortedArray) {
////        if (![[dict objectForKey:categoryId] isEqualToString:@""])
////        {
//            [contentString appendFormat:@"%@=%@&", categoryId, [dict objectForKey:categoryId]];
////        }
//    }
//    
//    //添加key字段
//    [contentString appendFormat:@"key=%@",MD5_Key];
//  
//    NSString *md5Sign =[contentString MD5EncodedString];
//    DBLOG(@"md5加密-->>%@,md5Sign->>%@",contentString,md5Sign);
//    return md5Sign;
//}

@end
